<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>酒店信息系统</title>
<link rel="stylesheet" href="__PUBLIC__/new_select/chosen.css">
</head>
<style>
.remove_a{color:gray;margin-right:10px;}
.remove_a:hover{color:#000}
#show_allData{width:700px;}
#show_allData table{
	line-height:35px;
	font-size:1em;
	padding:10px;
	width:700px;
	text-align:center;
	border:1px solid #e4e4e4;
}
</style>
<body>
{include file="public/head"}
</div>
<div class="content_2 clear">
{include file="admin/left"}
<script>
	function remove_a(key){
		var trname = 'tr[key="'+key+'"]';
		$(trname).remove();
	}
	function confirmAll(){
		var postdata="";
		var flag=0;
		var r1 = /^\d+(\.\d+)?$/;
		var r2 = /^\d+$/;
		$('.tr_addAll').each(function(index,domEle){
			var key = $(this).attr('key');
			var sybol = $('.all_input[name=addAll_sybol'+key+']:checked').val();
			var num = $('.all_input[name=addAll_num'+key+']').val();
			if(!num||!sybol){
				alert('数据不能有空值 不需要的项目请先移除');
				flag=1;
				return false;
			}
			if(!r1.test(num)&&!r2.test(num)){
				alert('数据只支持数字或小数');
				flag=1;
				return false;
			}
			var name = $('#addAll_name'+key).attr('value');
			postdata+='"'+name+'":"'+sybol+num+'",';
		});
		if(flag==1)return false;
		postdata = "{"+postdata.slice(0,-1)+"}";
		$.post('__APP__/admin/addAllNotice',{'data':postdata},function(data){
			if(data.result){
				alert(data.msg);
				window.location.reload();
			}else{
				alert(data.msg);
				return false;
			}
		},"json");
	}
	function confirmM(){
		var hotelId = $("#selHotel option:selected").val();
		var name = $('#addData_name').val();
		var sybol = $('.addData_fuhao:checked').val();
		var datas = $('#addData_data').val();
		if(!sybol||!name||!datas){
			alert('信息不完善');return;
		}
		name.replace(/(^\s*)|(\s*$)/g, "");
		datas.replace(/(^\s*)|(\s*$)/g, "");
		var con = confirm('确认保存该报警值？');
		if(!con){
			return false;
		}
		$.post('__APP__/admin/addOperNotice',{'hotelId':hotelId,'name':name,'sybol':sybol,'datas':datas},function(data){
			if(data.result){
				alert('添加成功');
				window.location.reload();
			}else{
				alert(data.msg);
				return false;
			}
		},'json');
	}
	function addData(){
		var nodata = $('#show_addData').attr('dataflag');
		if(nodata==1){
			alert('暂无该酒店数据 不能设置');return false;
		}
		$('#change_addData').hide();
		$('#show_addData').show();
		$('#addData_name').focus();
	}
	function addAllData(){
		$('#change_addData').hide();
		$('#show_allData').show();
	}
	function closeAllBox(){
		$('#show_allData').hide();
		$('#change_addData').show();
	}
	function deleteData(id){
		var a=confirm('确认删除该项报警值吗');
		if(!a){
			return false;	
		}
		$.post('__APP__/admin/deleteOperNotice',{'id':id},function(data){
			if(data.result){
				alert('删除成功');
				window.location.reload();
			}else{
				alert('删除失败');
			}
		},"json");
	}
	function selHotelId(){
		var hotelId = $("#selHotel option:selected").val();
		window.location.href="__APP__/admin/operationNotice?hotelId="+hotelId;
	}
	function closeAllAdd(){
		$("#show_allData").hide("fast",function(){$(this).css("display","none")});
	}
</script>
 <div class="content_3 left">
  <div class="content_3_wz"><img src="__PUBLIC__/images/dajt.png">系统管理 > 报警设置</div>
  <div class="content_3_fdj"><img src="__PUBLIC__/images/fdj.jpg"></div>
  <div class="content_3_xian"></div>
  <div class="content_3_ss clear">
  	<div>
  		<label>选择酒店：</label><select id="selHotel" onchange="selHotelId();" data-placeholder="选择酒店" class="chosen-select" style="width:350px;" tabindex="2">
  			 <option value=""></option>
  			<?php
  				if(isset($hotels)){
  					foreach($hotels as $val){
  						?>
  						<option <?php if($val['id']==$hotelId) echo "selected=selected"; ?> value="{$val['id']}">{$val['hotel']}</option>
  						<?php
  					}
  				}	
  			?>
  		</select>
  		
  	</div>
  <?php
  		if($noticeArr){
?>
  <table class="layui-table" lay-skin="line" >
     <thead >
      <tr>
          <td>参数</td>
          <td>报警值</td>
          <td></td>
      </tr>
      </thead>
<?php
			foreach($noticeArr as $key=>$value){
?>
	<tr id>
		<td>{$key}</td>
		<td>{$value['value']}</td>
		<td>
			<a href="#" class="layui-btn layui-btn-sm" onclick='deleteData("{$value['id']}")'>删除</a>
		</td>
	</tr>
<?php
		}
?>
  </table>
<?php
	}else{
	?>
	<p>未设置任何警报值</p>
	<?php
	}
  ?>
  <p id='change_addData' style='padding-left:30px;margin-top:10px;'><input type='button' value='增加数据' class='layui-btn layui-btn-sm layui-btn-warm' onclick="addData();" />
  <input type='button' value='一键增加' class='layui-btn layui-btn-sm layui-btn-warm' onclick="addAllData();" /></p>
  <div id='show_addData' style='display:none;' appsel="{$appselect}" dataflag="{$nodata}">
	  <table class="layui-table" lay-skin="line" >
	<tr>
		<td>参数名</td>
		<td>符号</td>
		<td>报警值(百分比请先修改为小数)</td>
		<td></td>
	</tr>
      <tr>
      	<td>
      		<select id='addData_name'>
      			<?php
      			if($namelist){
      			foreach($namelist as $value){
      			?>
      			<option>{$value}</option>
      			<?php
      			}
				}
      			?>
      		</select>
      	</td>
      	<td style='text-align: left'>
      		<input type='radio' name='addData_sybol' class='addData_fuhao' value='>='/>>=
      		<input type='radio' name='addData_sybol' class='addData_fuhao' value='<='/><=
      	</td>
		<td style='text-align: left;'><input type='text' size=6 id='addData_data'/></td>
		<td>
			<input id='close_change_add' type='button' class='layui-btn layui-btn-warm' value='提交' onclick="confirmM()"/>
		</td>
      </tr>
    </table>
  </div>
<div id='show_allData' style='display:none;' appsel="{$appselect}" class='show'>
	<table border="0" align="center"  cellpadding="0" bgcolor="#FFFFFF">
	<thead>
	<tr>
		<th>参数名</th>
		<th>符号</th>
		<th>报警值(百分比请先修改为小数)</th>
	</tr>
	</thead>
    <?php
    if($allnamelist){
      	foreach($allnamelist as $key=>$value){
    ?>
    <tr key="{$key}" class='tr_addAll'><td id="addAll_name{$key}" value="{$value}">{$value}</td>
    <td style='text-align: left'>
      	<input type='radio' name="addAll_sybol{$key}" class="all_input" value='>='/>>=
      	<input type='radio' name="addAll_sybol{$key}" class="all_input" value='<='/><=
    </td>
	<td style='text-align: center;'><input type='text' name='addAll_num{$key}' size='8' class="all_input"/></td>
	<td style='text-align: left;'><a onclick="remove_a({$key});" href='#' class='remove_a'>移除</a></td>
      </tr>
      <?php
      	}
	}
      ?>
      <tr><td colspan=4><input id='close_change_add' type='button' class='layui-btn layui-btn-warm' value='提交' onclick="confirmAll()"/>
      <input id='close_all_add' type='button' class='btn_04' value='取消' onclick='closeAllBox();'/></td></tr>
    </table>
  </div>
 <script src="__PUBLIC__/new_select/chosen.jquery.js" type="text/javascript"></script>
<script src="__PUBLIC__/new_select/docsupport/prism.js" type="text/javascript" charset="utf-8"></script>

  <script type="text/javascript">

    var config = {

      '.chosen-select'           : {},

      '.chosen-select-deselect'  : {allow_single_deselect:true},

      '.chosen-select-no-single' : {disable_search_threshold:10},

      '.chosen-select-no-results': {no_results_text:'Oops, nothing found!'},

      '.chosen-select-width'     : {width:"95%"}

    }

    for (var selector in config) {

      $(selector).chosen(config[selector]);

    }

  </script>
</body>
</html>

